<template>
    <div class="app-container">
        <el-drawer append-to-body v-model="drawer" :title="`入库明细【${detailInfo.ibDetailId}】关联任务列表`" direction="rtl"
            size="70%">
            <wms-form v-model:query-params="queryParams" :form-list="formList" @query="getList" label-width="88px"
                @export="handleExport">
                <el-col :span="1.5">
                    <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete"
                        v-hasPermi="['wms:task:remove']">取消</el-button>
                </el-col>
            </wms-form>
            <wms-table :loading="loading" :data-list="taskList" :column="column" :pageInfo="queryParams"
                @get-list="getList" @delete="handleDelete" @selection-change="handleSelectionChange"
                @row-click="handleRowClick" />
        </el-drawer>
    </div>
</template>

<script setup name="IbTask">
import { listTask, getTask, cancelTask, addTask, updateTask } from "@/api/wms/task";
import WmsTable from '@/components/WmsTable/index.vue'
import WmsForm from '@/components/WmsForm/index.vue'
import { data, column, formList } from './index.js'
import { ref, reactive, getCurrentInstance, onMounted } from "vue";

const { proxy } = getCurrentInstance();
const queryParams = reactive(data.queryParams);

const props = defineProps({
    detailInfo: {
        type: Object,
        require: true
    }
})

let drawer = defineModel(false)
const taskList = ref([]);
const loading = ref(true);
const ids = ref([]);
const single = ref(true);

/** 查询任务查询列表 */
function getList() {
    console.log("查询任务查询列表,props.detailInfo", props.detailInfo);
    queryParams.masterId = props.detailInfo.ibMasterId
    queryParams.detailId = props.detailInfo.ibDetailId
    loading.value = true;
    listTask(queryParams).then(response => {
        taskList.value = response.rows;
        queryParams.total = response.total;
        loading.value = false;
    });
}

/** 搜索按钮操作 */
function handleQuery() {
    queryParams.pageNum = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    queryParams.dateRange = [];
    proxy.resetForm("queryRef");
    handleQuery();
}

let multiple = ref(false)
// 多选框选中数据
function handleSelectionChange(selection) {
    ids.value = selection.map(item => item.taskId);
    single.value = selection.length != 1;
    multiple.value = !selection.length;
}


/** 取消按钮操作 */
function handleDelete(row) {
    const _taskIds = row.taskId || ids.value;
    proxy.$modal.confirm('是否确认删除任务查询编号为"' + _taskIds + '"的数据项？').then(function () {
        return cancelTask(_taskIds);
    }).then(response => {
        // 判断是否取消成功
        if (response.code == 200) {
            getList();
            proxy.$modal.msgSuccess(response.msg);
        } else {
            proxy.$modal.msgError(response.msg);
        }
    }).catch(() => { });
}

/** 导出按钮操作 */
function handleExport() {
    proxy.download('wms/task/export', {
        ...queryParams
    }, `task_${new Date().getTime()}.xlsx`)
}

const handleRowClick = (row) => {
    console.log('点击了任务信息：', 'row');
}

getList();
</script>
